setwd("")

# Required R packages
library(manifestoR)
library(tidyverse)
library(miceadds)
library(readstata13)
library(scales)

options(scipen=999)

# function for changing parts of a variable in tidyverse (from https://stackoverflow.com/questions/34096162/dplyr-mutate-replace-several-columns-on-a-subset-of-rows)
mutate_when <- function(data, ...) {
  dots <- eval(substitute(alist(...)))
  for (i in seq(1, length(dots), by = 2)) {
    condition <- eval(dots[[i]], envir = data)
    mutations <- eval(dots[[i + 1]], envir = data[condition, , drop = FALSE])
    data[condition, names(mutations)] <- mutations
  }
  data
}

###############################################

#### 1. DATASET CREATION #####

# Get the dataset: replication requires going to the manifesto project website, signing the user agreement and downloading the API key as per their instructions
# This uses the manifestoR package to access the CMP data
# See https://manifesto-project.wzb.eu/signup to sign up for access to CMP data, and to get an API key
# See https://manifesto-project.wzb.eu/information/documents/manifestoR for info on how to use the manifestoR package
# note that new versions of manifesto data are released and past data can be altered. Use the "2018-b" version for an exact replication of our results
# for the code below to work, the API key needs to be saved in your working directory
mp_setapikey("manifesto_apikey.txt")
mpds <- mp_maindataset(version="2018b")

# Create dependent variables (logit-scaled, negative = left); coding scheme is at https://manifesto-project.wzb.eu/coding_schemes/mp_v5
  
  mpds$govservices <- scale_logit(mpds,neg=c("per504","per506"),
                                  pos=c("per505","per507"))  
  
  mpds$freemarket <- scale_logit(mpds,neg=c("per403","per412","per413","per415","per404","per503","per701"),
                                 pos=c("per401","per402","per414","per702"))  
  
  mpds$libcon_env <- scale_logit(mpds,neg=c("per204","per501","per604","per705"),
                                 pos=c("per203","per603","per605"))
  
  mpds$nationalism <- scale_logit(mpds,neg=c("per607","per602"),pos=c("per608","per601"))
  
  mpds$libcon <- scale_logit(mpds,neg=c("per204","per604","per705"),
                             pos=c("per203","per603","per605"))



# Create dataset for analysis
  manifdata <- mpds %>% filter(countryname %in% c("Austria","Belgium","Bulgaria","Cyprus","Czech Republic",
                                                  "Denmark","Estonia","Finland","France","Germany","Greece",
                                                  "Hungary","Ireland","Italy","Latvia","Lithuania","Netherlands",
                                                  "Northern Ireland","Norway","Poland","Portugal","Slovakia",
                                                  "Slovenia","Spain","Sweden","Switzerland","United Kingdom","Luxembourg") & date>197112 & date<201712)
  
# Sort out Germany and Northern Ireland
  manifdata <- manifdata[!(manifdata$countryname=="Germany" & manifdata$date<198912),]  
  manifdata$countryname[manifdata$countryname=="United Kingdom" & (manifdata$partyname=="We Ourselves"|manifdata$partyname=="Ulster Unionist Party"|
                                                                     manifdata$partyname=="Democratic Unionist Party"|
                                                                     manifdata$partyname=="Social Democratic and Labour Party")] <- "Northern Ireland"
  manifdata$countryname[manifdata$countryname=="United Kingdom"] <- "Great Britain"

# Combine UK Liberal and SDP parties' vote shares pre 92: stood on identical manifestos
  manifdata$pervote[which(manifdata$party==51420 & manifdata$date==198306)] <- 11.642+13.727
  manifdata$pervote[which(manifdata$party==51420 & manifdata$date==198706)] <- 9.739+12.830
  manifdata$party[manifdata$party==51420] <- 51421
  manifdata <- manifdata[-which((manifdata$party==51330 & manifdata$date==198306)),]
  manifdata <- manifdata[-which((manifdata$party==51330 & manifdata$date==198706)),]

# France: RPR name change
  manifdata$partyabbrev[manifdata$party==31621 & manifdata$date==198106] <- "RPR"
  manifdata$partyabbrev[manifdata$party==31621 & manifdata$date==198603] <- "RPR"

  manifdata$party[manifdata$partyname=="Union for a New Majority - Gaullists/Conservatives"] <- 31625

# Year
  manifdata$year <-  rep(NA,length(manifdata$countryname))
  for(i in 1:length(manifdata$date)){
    manifdata$year[i] =paste(unlist(strsplit(as.character(manifdata$date[i]),split = character(0)))[1:4],sep="", collapse="")
  }

# Opinion data; merge into manifesto data
  load("europe_ideology.RData")

  for(i in 1:length(e$biennium)){
    e$year[i] =paste(unlist(strsplit(as.character(e$biennium[i]),split = character(0)))[6:9],sep="", collapse="")
  }
  
  e$year <- as.numeric(e$year)
  manifdata$year <- as.numeric(manifdata$year)
  manifdata$year.alt <- manifdata$year-1
  
  manifdata <- subset(manifdata, select=c("countryname","partyname","year","year.alt","edate","party","partyabbrev","parfam","pervote",
                                          "govservices","freemarket","libcon","libcon_env","nationalism"))
  
  manifdata$position.econabs=manifdata$position.econrel=manifdata$position.soc=manifdata$position.imm <- rep(NA,length(manifdata$year))
  
  for(i in 1:length(manifdata$year)){
    
    if(manifdata$year[i] %in% unique(e$year) & manifdata$countryname[i]!="Luxembourg"){
      manifdata$position.econabs[i] <- e$econ_abs_post_mean[which(e$country==manifdata$countryname[i] & 
                                                                    e$year==manifdata$year[i])]
      manifdata$position.econrel[i] <- e$econ_rel_post_mean[which(e$country==manifdata$countryname[i] & 
                                                                    e$year==manifdata$year[i])]
      manifdata$position.soc[i] <- e$soc_post_mean[which(e$country==manifdata$countryname[i] & 
                                                           e$year==manifdata$year[i])]
      manifdata$position.imm[i] <- e$immi_post_mean[which(e$country==manifdata$countryname[i] & 
                                                            e$year==manifdata$year[i])]
    }
    
    else if (manifdata$year.alt[i] %in% unique(e$year) & manifdata$countryname[i]!="Luxembourg"){
      manifdata$position.econabs[i] <- e$econ_abs_post_mean[which(e$country==manifdata$countryname[i] & 
                                                                    e$year==manifdata$year.alt[i])]
      manifdata$position.econrel[i] <- e$econ_rel_post_mean[which(e$country==manifdata$countryname[i] & 
                                                                    e$year==manifdata$year.alt[i])]
      manifdata$position.soc[i] <- e$soc_post_mean[which(e$country==manifdata$countryname[i] & 
                                                           e$year==manifdata$year.alt[i])]
      manifdata$position.imm[i] <- e$immi_post_mean[which(e$country==manifdata$countryname[i] & 
                                                            e$year==manifdata$year.alt[i])]
    }
  }
  

# Eurobarometer Left-Right Data
  manifdata$country_year <- paste(manifdata$countryname,manifdata$year,sep="")

  # bring in eurobarometer data
  lr_data <- read.dta13("final_eblrdata_alleurope_repr.dta")
  lr_data <- lr_data %>% mutate(lrs = as.numeric(as.character(lrs)),
                                country = as.character(country),
                                country = recode(country,"austria"="Austria","belgium"="Belgium","denmark"="Denmark","finland"="Finland","france"="France",
                                                 "GERMANY-WEST"="Germany","GREAT BRITAIN"="Great Britain","greece"="Greece","ireland"="Ireland",
                                                 "italy"="Italy","luxembourg"="Luxembourg","netherlands"="Netherlands","NORTHERN IRELAND"="Northern Ireland",
                                                 "norway"="Norway","portugal"="Portugal","sweden"="Sweden","spain"="Spain")) %>%
    group_by(year,country) %>%
    summarise(eblr = weighted.mean(lrs,weight,na.rm=T))
  
  lr_data$country_year <- paste(lr_data$country,lr_data$year,sep="")

  # Bring eblr data into the manifesto dataset
  manifdata$eblr <- rep(NA,length(manifdata$countryname))
  for(i in 1:length(manifdata$countryname)){
    
    if(manifdata$country_year[i] %in% lr_data$country_year){
      manifdata$eblr[i] <- lr_data$eblr[lr_data$country_year==manifdata$country_year[i]]} 
    
  }

# Remove parties with only one election
  nelections <- manifdata %>% group_by(party) %>% summarise(nelec = length(pervote))
  manifdata$nelec <- rep(NA,length(manifdata$countryname))
  for(i in 1:length(manifdata$countryname)){
    manifdata$nelec[i] <- nelections$nelec[nelections$party==manifdata$party[i]]
  }
  
  manifdata <- manifdata %>% filter(nelec>1)

# calc average percentage of the vote
  percvote <- manifdata %>% group_by(party) %>% summarise(percvote = mean(pervote,na.rm=T))
  
  percvote$country=percvote$partyname <- c()
  for(i in 1:length(percvote$party)){
    percvote$partyname[i] <- manifdata$partyname[manifdata$party==percvote$party[i]]
    percvote$country[i] <- manifdata$countryname[manifdata$party==percvote$party[i]]
  }
  
  manifdata$vote_av <- rep(NA,length(manifdata$countryname))
  for(i in 1:length(manifdata$countryname)){
    manifdata$vote_av[i] <- percvote$percvote[percvote$party==manifdata$party[i]]
  }



# Take first differences and lags
  manifdata <- manifdata[with(manifdata, order(manifdata$party)), ]
  
  fd_vote=fd_vote_lag=fd_position.imm=fd_position.soc=fd_position.soc_env=fd_position.econrel=fd_position.econabs <- c()
  fd_govservices=fd_freemarket=fd_libcon=fd_libcon_env=fd_nationalism <- c()
  fd_govservices_lag=fd_freemarket_lag=fd_libcon_lag=fd_libcon_env_lag=fd_nationalism_lag <- c()
  
  for(i in 1:length(unique(manifdata$party))){
    govservices <- c(NA, diff(manifdata$govservices[which(manifdata$party==unique(manifdata$party)[i])]) )
    govservices_lag <- c(NA,govservices[1:(length(govservices)-1)])
    freemarket <- c(NA, diff(manifdata$freemarket[which(manifdata$party==unique(manifdata$party)[i])]) )
    freemarket_lag <- c(NA,freemarket[1:(length(freemarket)-1)])
    libcon <- c(NA, diff(manifdata$libcon[which(manifdata$party==unique(manifdata$party)[i])]) )
    libcon_lag <- c(NA,libcon[1:(length(libcon)-1)])
    libcon_env <- c(NA, diff(manifdata$libcon_env[which(manifdata$party==unique(manifdata$party)[i])]) )
    libcon_env_lag <- c(NA,libcon_env[1:(length(libcon_env)-1)])
    nationalism <- c(NA, diff(manifdata$nationalism[which(manifdata$party==unique(manifdata$party)[i])]) )
    nationalism_lag <- c(NA,nationalism[1:(length(nationalism)-1)])
    
    vote <- c(NA, diff(manifdata$pervote[which(manifdata$party==unique(manifdata$party)[i])]) )
    vote_lag <- c(NA,vote[1:(length(vote)-1)])
    
    imm <- c(NA, diff(manifdata$position.imm[which(manifdata$party==unique(manifdata$party)[i])]) )
    soc <- c(NA, diff(manifdata$position.soc[which(manifdata$party==unique(manifdata$party)[i])]) )
    econrel <- c(NA, diff(manifdata$position.econrel[which(manifdata$party==unique(manifdata$party)[i])]) )
    econabs <- c(NA, diff(manifdata$position.econabs[which(manifdata$party==unique(manifdata$party)[i])]) )
    
    fd_govservices <- c(fd_govservices,govservices)
    fd_govservices_lag <- c(fd_govservices_lag,govservices_lag)
    fd_freemarket <- c(fd_freemarket,freemarket)
    fd_freemarket_lag <- c(fd_freemarket_lag,freemarket_lag)
    fd_libcon <- c(fd_libcon,libcon)
    fd_libcon_lag <- c(fd_libcon_lag,libcon_lag)
    fd_libcon_env <- c(fd_libcon_env,libcon_env)
    fd_libcon_env_lag <- c(fd_libcon_env_lag,libcon_env_lag)
    fd_nationalism <- c(fd_nationalism,nationalism)
    fd_nationalism_lag <- c(fd_nationalism_lag,nationalism_lag)
    
    fd_vote <- c(fd_vote,vote)
    fd_vote_lag <- c(fd_vote_lag,vote_lag)
    
    fd_position.imm <- c(fd_position.imm,imm)
    fd_position.soc <- c(fd_position.soc,soc)
    fd_position.econrel <- c(fd_position.econrel,econrel)
    fd_position.econabs <- c(fd_position.econabs,econabs)
  }

  # in dataset
  manifdata$pervote_fd <- fd_vote
  manifdata$pervote_fd_lag <- fd_vote_lag
  
  manifdata$govservices_fd <- fd_govservices
  manifdata$freemarket_fd <- fd_freemarket
  manifdata$libcon_fd <- fd_libcon
  manifdata$libcon_env_fd <- fd_libcon_env
  manifdata$nationalism_fd <- fd_nationalism
  
  manifdata$govservices_fd_lag <- fd_govservices_lag
  manifdata$freemarket_fd_lag <- fd_freemarket_lag
  manifdata$libcon_fd_lag <- fd_libcon_lag
  manifdata$libcon_env_fd_lag <- fd_libcon_env_lag
  manifdata$nationalism_fd_lag <- fd_nationalism_lag
  
  manifdata$position.imm_fd <- fd_position.imm
  manifdata$position.soc_fd <- fd_position.soc
  manifdata$position.econrel_fd <- fd_position.econrel
  manifdata$position.econabs_fd <- fd_position.econabs
  
  rm(fd_vote,fd_vote_lag,vote,vote_lag,imm,soc,econrel,econabs,fd_position.imm,fd_position.soc,
     fd_position.econrel,fd_position.econabs,fd_govservices,fd_freemarket,fd_libcon,fd_libcon_env,fd_nationalism,fd_govservices_lag,fd_freemarket_lag,
     fd_libcon_lag,fd_libcon_env_lag,fd_nationalism_lag,freemarket,freemarket_lag,govservices,govservices_lag,libcon,libcon_lag,libcon_env,
     libcon_env_lag,nationalism,nationalism_lag)

# niche party dummies,interactions
  manifdata$niche <- ifelse((manifdata$parfam==10|manifdata$parfam==20|manifdata$parfam==70),1,0)
  
  manifdata$niche_position.immfd <- manifdata$niche*manifdata$position.imm_fd
  manifdata$niche_position.socfd <- manifdata$niche*manifdata$position.soc_fd
  manifdata$niche_position.econrelfd <- manifdata$niche*manifdata$position.econrel_fd
  manifdata$niche_position.econabsfd <- manifdata$niche*manifdata$position.econabs_fd
  
  manifdata$pervote_govservices_lag <- manifdata$govservices_fd_lag*manifdata$pervote_fd_lag
  manifdata$pervote_freemarket_lag <- manifdata$freemarket_fd_lag*manifdata$pervote_fd_lag
  manifdata$pervote_libcon_lag <- manifdata$libcon_fd_lag*manifdata$pervote_fd_lag
  manifdata$pervote_libcon_env_lag <- manifdata$libcon_env_fd_lag*manifdata$pervote_fd_lag
  manifdata$pervote_nationalism_lag <- manifdata$nationalism_fd_lag*manifdata$pervote_fd_lag
  

# Create clusters; cut down years  
  manifdata$clusters <- c(rep(NA, length(manifdata$countryname)))
  max_index <- 0

  #loop through countries, then years
  for(i in 1:length(unique(manifdata$countryname))){
    
    years <- c(sort(unique(manifdata$year[manifdata$countryname==unique(manifdata$countryname)[i]])))
    
    # assign a cluster number to each observation for country i
    for(j in 1:length(manifdata$countryname[manifdata$countryname==unique(manifdata$countryname)[i]])){
      manifdata$clusters[manifdata$countryname==unique(manifdata$countryname)[i]][j] <- max_index + 
        which(years == manifdata$year[manifdata$countryname==unique(manifdata$countryname)[i]][j])
    }
    # re-set max index each time so that we get unique clusters for each country
    max_index <- max_index + length(unique(manifdata$year[manifdata$countryname==unique(manifdata$countryname)[i]]))
  }

# 'benign' and 'harmful' pub opn shifts

  # Left and right dummies
  manifdata$leftparty <- ifelse((manifdata$parfam==10|manifdata$parfam==20|manifdata$parfam==30),1,0)
  manifdata$rightparty <- ifelse((manifdata$parfam==50|manifdata$parfam==60|manifdata$parfam==70),1,0)
  
  #'disadvantaged' dummy, absolute econ
  manifdata$disad_econabs <- rep(NA, length(manifdata$countryname))
  for(i in 1:length(manifdata$countryname)){
    
    if(is.na(manifdata$position.econabs_fd[i])==FALSE & manifdata$leftparty[i] == 1 & manifdata$position.econabs_fd[i]>0){
      manifdata$disad_econabs[i] <- 1
    } 
    
    else if(is.na(manifdata$position.econabs_fd[i])==FALSE & manifdata$rightparty[i] == 1 & manifdata$position.econabs_fd[i]<0) {
      manifdata$disad_econabs[i] <- 1
    }
    
    else{manifdata$disad_econabs[i] <- 0}
    
  }
  
  # 1 minus it
  manifdata$not_disad_econabs <- 1 - manifdata$disad_econabs
  
  # interactions with pub opn shifts
  manifdata$harmful_econabs <- manifdata$disad_econabs*manifdata$position.econabs_fd
  manifdata$benign_econabs <- manifdata$not_disad_econabs*manifdata$position.econabs_fd
  
  #####
  
  #'disadvantaged' dummy, relative econ
  manifdata$disad_econrel <- rep(NA, length(manifdata$countryname))
  for(i in 1:length(manifdata$countryname)){
    
    if(is.na(manifdata$position.econrel_fd[i])==FALSE & manifdata$leftparty[i] == 1 & manifdata$position.econrel_fd[i]>0){
      manifdata$disad_econrel[i] <- 1
    } 
    
    else if(is.na(manifdata$position.econrel_fd[i])==FALSE & manifdata$rightparty[i] == 1 & manifdata$position.econrel_fd[i]<0) {
      manifdata$disad_econrel[i] <- 1
    }
    
    else{manifdata$disad_econrel[i] <- 0}
    
  }
  
  # 1 minus it
  manifdata$not_disad_econrel <- 1 - manifdata$disad_econrel
  
  # interactions with pub opn shifts
  manifdata$harmful_econrel <- manifdata$disad_econrel*manifdata$position.econrel_fd
  manifdata$benign_econrel <- manifdata$not_disad_econrel*manifdata$position.econrel_fd
  
  #####
  
  #'disadvantaged' dummy, social
  manifdata$disad_soc <- rep(NA, length(manifdata$countryname))
  for(i in 1:length(manifdata$countryname)){
    
    if(is.na(manifdata$position.soc_fd[i])==FALSE & manifdata$leftparty[i] == 1 & manifdata$position.soc_fd[i]>0){
      manifdata$disad_soc[i] <- 1
    } 
    
    else if(is.na(manifdata$position.soc_fd[i])==FALSE & manifdata$rightparty[i] == 1 & manifdata$position.soc_fd[i]<0) {
      manifdata$disad_soc[i] <- 1
    }
    
    else{manifdata$disad_soc[i] <- 0}
    
  }
  
  # 1 minus it
  manifdata$not_disad_soc <- 1 - manifdata$disad_soc
  
  # interactions with pub opn shifts
  manifdata$harmful_soc <- manifdata$disad_soc*manifdata$position.soc_fd
  manifdata$benign_soc <- manifdata$not_disad_soc*manifdata$position.soc_fd
  
  #####
  
  #'disadvantaged' dummy, immigration
  manifdata$disad_imm <- rep(NA, length(manifdata$countryname))
  for(i in 1:length(manifdata$countryname)){
    
    if(is.na(manifdata$position.imm_fd[i])==FALSE & manifdata$leftparty[i] == 1 & manifdata$position.imm_fd[i]>0){
      manifdata$disad_imm[i] <- 1
    } 
    
    else if(is.na(manifdata$position.imm_fd[i])==FALSE & manifdata$rightparty[i] == 1 & manifdata$position.imm_fd[i]<0) {
      manifdata$disad_imm[i] <- 1
    }
    
    else{manifdata$disad_imm[i] <- 0}
    
  }
  
  # 1 minus it
  manifdata$not_disad_imm <- 1 - manifdata$disad_imm
  
  # interactions with pub opn shifts
  manifdata$harmful_imm <- manifdata$disad_imm*manifdata$position.imm_fd
  manifdata$benign_imm <- manifdata$not_disad_imm*manifdata$position.imm_fd


# Final Dataset
save(manifdata,file="manifdata_final.Rda")

# figure 1 in the appendix
  pdf(file="lr_overtime.pdf")
  ggplot(manifdata %>% group_by(countryname,year) %>% summarise(eblr = mean(eblr)) %>%
           filter(!(countryname=="Northern Ireland"|countryname=="Norway"|countryname=="Switzerland") & year>1975),
         aes(x=year,y=eblr)) +
    geom_line() +
    facet_wrap(~countryname) +
    scale_x_continuous(name="") +
    scale_y_continuous(name="Left-Right Position") +
    coord_cartesian(ylim=c(4,7)) +
    theme(axis.text.x = element_text(size=7))
  dev.off()

# figure 2 in the appendix 
  manifdata$parfam_plot <- rep(NA,length(manifdata$year))
  manifdata$parfam_plot[manifdata$parfam==10] <- 1
  manifdata$parfam_plot[manifdata$parfam==20] <- 2
  manifdata$parfam_plot[manifdata$parfam==30] <- 3
  manifdata$parfam_plot[manifdata$parfam==40] <- 4
  manifdata$parfam_plot[manifdata$parfam==50] <- 5
  manifdata$parfam_plot[manifdata$parfam==60] <- 6
  manifdata$parfam_plot[manifdata$parfam==70] <- 7
  
  pdf(file="domain_scales.pdf")
  ggplot(manifdata %>% gather("scale","party_pos",c("govservices","freemarket","libcon_env","nationalism")) %>% 
           mutate(scale1=factor(scale,labels=c("Absolute Economic","Relative Economic","Social/Postmaterial Issues","Immigration/Nationalism"))) %>% 
           filter(is.na(parfam_plot) == FALSE) %>%
           mutate_when(party==13951, list(parfam=70),
                       party==14820, list(parfam=70)), 
         aes(x=factor(parfam_plot), y=party_pos)) + 
    facet_wrap(~scale1) +
    geom_boxplot() +
    coord_flip() +
    scale_y_continuous(name="Party Position (Left-Right)",labels=waiver()) +
    scale_x_discrete(name="", labels =c("Green","Socialist","Social\nDemocratic","Liberal","Christian\nDemocratic","Conservative","Nationalist"))
  dev.off()


# description of the variables, as referenced in text of main paper
  mean(manifdata$freemarket, na.rm=T)
  mean(manifdata$govservices, na.rm=T)
  mean(manifdata$libcon_env, na.rm=T)
  mean(manifdata$nationalism, na.rm=T) 
  sd(manifdata$freemarket, na.rm=T)
  sd(manifdata$govservices, na.rm=T)
  sd(manifdata$libcon_env, na.rm=T)
  sd(manifdata$nationalism, na.rm=T) 
  
  mean(manifdata$position.econabs, na.rm=T)
  mean(manifdata$position.econrel, na.rm=T)
  mean(manifdata$position.soc, na.rm=T)
  mean(manifdata$position.imm, na.rm=T) 
  sd(manifdata$position.econabs, na.rm=T)
  sd(manifdata$position.econrel, na.rm=T)
  sd(manifdata$position.soc, na.rm=T)
  sd(manifdata$position.imm, na.rm=T) 

###############################################
  
#### 2. ANALYSIS ##### 
 
## Table 2: domain-specific representation, general ##

  reg1 <- lm.cluster(freemarket_fd ~ 0 + position.econabs_fd + freemarket_fd_lag + pervote_fd_lag + 
                       pervote_freemarket_lag + factor(countryname),
                     data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                    party==13951, list(parfam=70),
                                                    party==14820, list(niche=1),
                                                    party==14820, list(parfam=70)) %>% 
                       filter(vote_av>=1 & parfam<80),
                     cluster="clusters")
  summary(reg1)
  length(reg1$lm_res[[2]]) 

  reg2 <- lm.cluster(govservices_fd ~ 0 + position.econrel_fd + govservices_fd_lag + pervote_fd_lag + 
                       pervote_govservices_lag + factor(countryname),
                     data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                    party==13951, list(parfam=70),
                                                    party==14820, list(niche=1),
                                                    party==14820, list(parfam=70)) %>% 
                       filter(vote_av>=1 & parfam<80),
                     cluster="clusters")
  summary(reg2)
  length(reg2$lm_res[[2]]) 
  
  reg3 <- lm.cluster(libcon_env_fd ~ 0 + position.soc_fd + libcon_env_fd_lag + pervote_fd_lag + 
                        pervote_libcon_env_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg3)
  length(reg3$lm_res[[2]]) 

  
  
  reg4 <- lm.cluster(nationalism_fd ~ 0 + position.imm_fd + nationalism_fd_lag + pervote_fd_lag + 
                        pervote_nationalism_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg4)
  length(reg4$lm_res[[2]]) 
  
  # interpretation in text
  a <- sd(manifdata$nationalism,na.rm=T)
  b <- sd(manifdata$position.imm, na.rm=T)
  (reg4$lm_res[[1]][1] * b)/a
  
  
## Table 3: domain-specific representation, harmful/benign
  
  reg5 <- lm.cluster(freemarket_fd ~ 0 + harmful_econabs + benign_econabs + freemarket_fd_lag + pervote_fd_lag + 
                        pervote_freemarket_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg5)
  length(reg5$lm_res[[2]]) 
  
  reg6 <- lm.cluster(govservices_fd ~ 0 + harmful_econrel + benign_econrel + govservices_fd_lag + pervote_fd_lag + 
                        pervote_govservices_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg6)
  length(reg6$lm_res[[2]]) 
  
  reg7 <- lm.cluster(libcon_env_fd ~ 0 + harmful_soc + benign_soc + libcon_env_fd_lag + pervote_fd_lag + 
                        pervote_libcon_env_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg7)
  length(reg7$lm_res[[2]]) 
  
  reg8 <- lm.cluster(nationalism_fd ~ 0 + harmful_imm + benign_imm + nationalism_fd_lag + pervote_fd_lag + 
                        pervote_nationalism_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg8)
  length(reg8$lm_res[[2]]) 
  
   
  
## Table 4:  domain-specific representation, niche/mainstream
  
  reg9 <- lm.cluster(freemarket_fd ~ 0 + position.econabs_fd + niche + niche_position.econabsfd + freemarket_fd_lag + pervote_fd_lag + 
                        pervote_freemarket_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg9)
  length(reg9$lm_res[[2]]) 
  
  reg10 <- lm.cluster(govservices_fd ~ 0 + position.econrel_fd + niche + niche_position.econrelfd + govservices_fd_lag + pervote_fd_lag + 
                        pervote_govservices_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg10)
  length(reg10$lm_res[[2]]) 
  
  
  
  reg11 <- lm.cluster(libcon_env_fd ~ 0 + position.soc_fd + niche + niche_position.socfd + libcon_env_fd_lag + pervote_fd_lag + 
                        pervote_libcon_env_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg11)
  length(reg11$lm_res[[2]]) 
  
  reg12 <- lm.cluster(nationalism_fd ~ 0 + position.imm_fd + niche + niche_position.immfd + nationalism_fd_lag + pervote_fd_lag + 
                        pervote_nationalism_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg12)
  length(reg12$lm_res[[2]]) 
  
  
  
 
  
  
###############################################
  
  #### 3. APPENDIX ANALYSIS #####   
 
  
  #### 3A. WESTERN EUROPE ONLY ####
  
  # general: western europe
  reg1a <- lm.cluster(freemarket_fd ~ 0 + position.econabs_fd + freemarket_fd_lag + pervote_fd_lag + 
                       pervote_freemarket_lag + factor(countryname),
                     data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                    party==13951, list(parfam=70),
                                                    party==14820, list(niche=1),
                                                    party==14820, list(parfam=70)) %>% 
                       filter(countryname %in% c("Austria","Belgium","Denmark","Finland","France","Germany",
                                                 "Great Britain","Greece","Ireland","Italy","Netherlands","Sweden",
                                                 "Switzerland","Portugal","Spain") &  vote_av>=1 & parfam<80),
                     cluster="clusters")
  summary(reg1a)
  length(reg1a$lm_res[[2]])  
  
  reg2a <- lm.cluster(govservices_fd ~ 0 + position.econrel_fd + govservices_fd_lag + pervote_fd_lag + 
                       pervote_govservices_lag + factor(countryname),
                     data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                    party==13951, list(parfam=70),
                                                    party==14820, list(niche=1),
                                                    party==14820, list(parfam=70)) %>% 
                       filter(countryname %in% c("Austria","Belgium","Denmark","Finland","France","Germany",
                                                 "Great Britain","Greece","Ireland","Italy","Netherlands","Sweden",
                                                 "Switzerland","Portugal","Spain") &  vote_av>=1 & parfam<80),
                     cluster="clusters")
  summary(reg2a)
  length(reg2a$lm_res[[2]]) 
  
  reg3a <- lm.cluster(libcon_env_fd ~ 0 + position.soc_fd + libcon_env_fd_lag + pervote_fd_lag + 
                        pervote_libcon_env_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(countryname %in% c("Austria","Belgium","Denmark","Finland","France","Germany",
                                                  "Great Britain","Greece","Ireland","Italy","Netherlands","Sweden",
                                                  "Switzerland","Portugal","Spain") &  vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg3a)
  length(reg3a$lm_res[[2]]) 

  
  reg4a <- lm.cluster(nationalism_fd ~ 0 + position.imm_fd + nationalism_fd_lag + pervote_fd_lag + 
                        pervote_nationalism_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(countryname %in% c("Austria","Belgium","Denmark","Finland","France","Germany",
                                                  "Great Britain","Greece","Ireland","Italy","Netherlands","Sweden",
                                                  "Switzerland","Portugal","Spain") &  vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg4a)
  length(reg4a$lm_res[[2]]) 
  
  #################         
  
  # harmful/benign western europe
  
  reg5a <- lm.cluster(freemarket_fd ~ 0 + harmful_econabs + benign_econabs + freemarket_fd_lag + pervote_fd_lag + 
                        pervote_freemarket_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(countryname %in% c("Austria","Belgium","Denmark","Finland","France","Germany",
                                                  "Great Britain","Greece","Ireland","Italy","Netherlands","Sweden",
                                                  "Switzerland","Portugal","Spain") &  vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg5a)
  length(reg5a$lm_res[[2]]) 
  
  reg6a <- lm.cluster(govservices_fd ~ 0 + harmful_econrel + benign_econrel + govservices_fd_lag + pervote_fd_lag + 
                        pervote_govservices_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(countryname %in% c("Austria","Belgium","Denmark","Finland","France","Germany",
                                                  "Great Britain","Greece","Ireland","Italy","Netherlands","Sweden",
                                                  "Switzerland","Portugal","Spain") &  vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg6a)
  length(reg6a$lm_res[[2]]) 
  
  reg7a <- lm.cluster(libcon_env_fd ~ 0 + harmful_soc + benign_soc + libcon_env_fd_lag + pervote_fd_lag + 
                        pervote_libcon_env_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(countryname %in% c("Austria","Belgium","Denmark","Finland","France","Germany",
                                                  "Great Britain","Greece","Ireland","Italy","Netherlands","Sweden",
                                                  "Switzerland","Portugal","Spain") &  vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg7a)
  length(reg7a$lm_res[[2]]) 
  
  reg8a <- lm.cluster(nationalism_fd ~ 0 + harmful_imm + benign_imm + nationalism_fd_lag + pervote_fd_lag + 
                        pervote_nationalism_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(countryname %in% c("Austria","Belgium","Denmark","Finland","France","Germany",
                                                  "Great Britain","Greece","Ireland","Italy","Netherlands","Sweden",
                                                  "Switzerland","Portugal","Spain") &  vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg8a)
  length(reg8a$lm_res[[2]]) 
  

  
  #################         
  
  # niche/mainstream: western europe
  
  reg9a <- lm.cluster(freemarket_fd ~ 0 + position.econabs_fd + niche + niche_position.econabsfd + freemarket_fd_lag + pervote_fd_lag + 
                        pervote_freemarket_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(countryname %in% c("Austria","Belgium","Denmark","Finland","France","Germany",
                                                  "Great Britain","Greece","Ireland","Italy","Netherlands","Sweden",
                                                  "Switzerland","Portugal","Spain") &  vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg9a)
  length(reg9a$lm_res[[2]]) 
  
  reg10a <- lm.cluster(govservices_fd ~ 0 + position.econrel_fd + niche + niche_position.econrelfd + govservices_fd_lag + pervote_fd_lag + 
                        pervote_govservices_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(countryname %in% c("Austria","Belgium","Denmark","Finland","France","Germany",
                                                  "Great Britain","Greece","Ireland","Italy","Netherlands","Sweden",
                                                  "Switzerland","Portugal","Spain") &  vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg10a)
  length(reg10a$lm_res[[2]]) 
  
  
  
  reg11a <- lm.cluster(libcon_env_fd ~ 0 + position.soc_fd + niche + niche_position.socfd + libcon_env_fd_lag + pervote_fd_lag + 
                        pervote_libcon_env_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(countryname %in% c("Austria","Belgium","Denmark","Finland","France","Germany",
                                                  "Great Britain","Greece","Ireland","Italy","Netherlands","Sweden",
                                                  "Switzerland","Portugal","Spain") &  vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg11a)
  length(reg11a$lm_res[[2]]) 
  
  reg12a <- lm.cluster(nationalism_fd ~ 0 + position.imm_fd + niche + niche_position.immfd + nationalism_fd_lag + pervote_fd_lag + 
                        pervote_nationalism_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(countryname %in% c("Austria","Belgium","Denmark","Finland","France","Germany",
                                                  "Great Britain","Greece","Ireland","Italy","Netherlands","Sweden",
                                                  "Switzerland","Portugal","Spain") &  vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg12a)
  length(reg12a$lm_res[[2]]) 
  
  
  
  
#######################################
  
  #### 3B. PRE-1999 ####
  
  # general: pre-99
  reg1b <- lm.cluster(freemarket_fd ~ 0 + position.econabs_fd + freemarket_fd_lag + pervote_fd_lag + 
                       pervote_freemarket_lag + factor(countryname),
                     data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                    party==13951, list(parfam=70),
                                                    party==14820, list(niche=1),
                                                    party==14820, list(parfam=70)) %>% 
                       filter(vote_av>=1 & parfam<80 & year<1999),
                     cluster="clusters")
  summary(reg1b)
  length(reg1b$lm_res[[2]])  
  
  reg2b <- lm.cluster(govservices_fd ~ 0 + position.econrel_fd + govservices_fd_lag + pervote_fd_lag + 
                       pervote_govservices_lag + factor(countryname),
                     data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                    party==13951, list(parfam=70),
                                                    party==14820, list(niche=1),
                                                    party==14820, list(parfam=70)) %>% 
                       filter(vote_av>=1 & parfam<80 & year<1999),
                     cluster="clusters")
  summary(reg2b)
  length(reg2b$lm_res[[2]]) 
  
  reg3b <- lm.cluster(libcon_env_fd ~ 0 + position.soc_fd + libcon_env_fd_lag + pervote_fd_lag + 
                        pervote_libcon_env_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80 & year<1999),
                      cluster="clusters")
  summary(reg3b)
  length(reg3b$lm_res[[2]]) 

  reg4b <- lm.cluster(nationalism_fd ~ 0 + position.imm_fd + nationalism_fd_lag + pervote_fd_lag + 
                        pervote_nationalism_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80 & year<1999),
                      cluster="clusters")
  summary(reg4b)
  length(reg4b$lm_res[[2]]) 
  
  #################         
  
  # harmful/benign: pre-99
  
  reg5b <- lm.cluster(freemarket_fd ~ 0 + harmful_econabs + benign_econabs + freemarket_fd_lag + pervote_fd_lag + 
                        pervote_freemarket_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80 & year<1999),
                      cluster="clusters")
  summary(reg5b)
  length(reg5b$lm_res[[2]]) 
  
  reg6b <- lm.cluster(govservices_fd ~ 0 + harmful_econrel + benign_econrel + govservices_fd_lag + pervote_fd_lag + 
                        pervote_govservices_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80 & year<1999),
                      cluster="clusters")
  summary(reg6b)
  length(reg6b$lm_res[[2]]) 
  
  reg7b <- lm.cluster(libcon_env_fd ~ 0 + harmful_soc + benign_soc + libcon_env_fd_lag + pervote_fd_lag + 
                        pervote_libcon_env_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80 & year<1999),
                      cluster="clusters")
  summary(reg7b)
  length(reg7b$lm_res[[2]]) 
  
  reg8b <- lm.cluster(nationalism_fd ~ 0 + harmful_imm + benign_imm + nationalism_fd_lag + pervote_fd_lag + 
                        pervote_nationalism_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80 & year<1999),
                      cluster="clusters")
  summary(reg8b)
  length(reg8b$lm_res[[2]]) 
  
  #################         
  
  # niche/mainstream: pre-99
  
  reg9b <- lm.cluster(freemarket_fd ~ 0 + position.econabs_fd + niche + niche_position.econabsfd + freemarket_fd_lag + pervote_fd_lag + 
                        pervote_freemarket_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80 & year<1999),
                      cluster="clusters")
  summary(reg9b)
  length(reg9b$lm_res[[2]]) 
  
  reg10b <- lm.cluster(govservices_fd ~ 0 + position.econrel_fd + niche + niche_position.econrelfd + govservices_fd_lag + pervote_fd_lag + 
                        pervote_govservices_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80 & year<1999),
                      cluster="clusters")
  summary(reg10b)
  length(reg10b$lm_res[[2]]) 
  
  
  
  reg11b <- lm.cluster(libcon_env_fd ~ 0 + position.soc_fd + niche + niche_position.socfd + libcon_env_fd_lag + pervote_fd_lag + 
                        pervote_libcon_env_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80 & year<1999),
                      cluster="clusters")
  summary(reg11b)
  length(reg11b$lm_res[[2]]) 
  
  reg12b <- lm.cluster(nationalism_fd ~ 0 + position.imm_fd + niche + niche_position.immfd + nationalism_fd_lag + pervote_fd_lag + 
                        pervote_nationalism_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80 & year<1999),
                      cluster="clusters")
  summary(reg12b)
  length(reg12b$lm_res[[2]]) 
  
  
  ###################
  
  #### 3C. SOCIAL ISSUES WITHOUT ENVIRONMENT  ####
  
  reg3c <- lm.cluster(libcon_fd ~ 0 + position.soc_fd + libcon_fd_lag + pervote_fd_lag + 
                        pervote_libcon_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg3c)
  length(reg3c$lm_res[[2]]) 
  
  
  reg7c <- lm.cluster(libcon_fd ~ 0 + position.soc_fd + niche + niche_position.socfd + libcon_fd_lag + pervote_fd_lag + 
                        pervote_libcon_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg7c)
  length(reg7c$lm_res[[2]]) 
  
  
  reg11c <- lm.cluster(libcon_fd ~ 0 + harmful_soc + benign_soc + libcon_fd_lag + pervote_fd_lag + 
                        pervote_libcon_lag + factor(countryname),
                      data=manifdata %>% mutate_when(party==13951, list(niche=1),
                                                     party==13951, list(parfam=70),
                                                     party==14820, list(niche=1),
                                                     party==14820, list(parfam=70)) %>% 
                        filter(vote_av>=1 & parfam<80),
                      cluster="clusters")
  summary(reg11c)
  length(reg11c$lm_res[[2]]) 
  

  

  
  
  